/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.rpc.service.plugins  
 */
package com.apache.rpc.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.rpc.manager.DynamicDatabaseManager;

/**
 * description:  复制数据到另一张表中
 * @author Hou Dayu 创建时间：2015-1-19  
 * @Copyright(c)2014:
 */
public class DynamicDatabasePlugin implements PluginConnector {

	private DynamicDatabaseManager dynamicDatabaseManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity result = new ResultEntity();
		String newTableName = String.valueOf(param.getParams("targetTableName"));
		String oldTableName = String.valueOf(param.getParams("sourceTableName"));
		if (Validator.isNotNull(newTableName) && Validator.isNotNull(oldTableName)) {
			String columns = Validator.getDefaultStr(String.valueOf(param.getParams("columns")), "");
			String key = "DynamicDatabase";
			String condition = Validator.getDefaultStr(String.valueOf(param.getParams("condition")), "");
			ParamsVo vo = new ParamsVo();
			vo.setKey(key);
			vo.setParams("targetTableName", newTableName);
			vo.setParams("sourceTableName", oldTableName);
			vo.setParams("columns", columns);
			vo.setParams("condition", condition);
			vo.setParams("isDelete", param.getParams("isDelete"));
			String mark = dynamicDatabaseManager.saveInfo(vo);
			result.setEntity(mark);
			result.setResult("true");
			result.setMessage("接口调用成功");
		} else {
			result.setResult("false");
			result.setMessage("接口必要参数请正确填写");
		}
		return result;
	}

	public void setDynamicDatabaseManager(DynamicDatabaseManager dynamicDatabaseManager) {
		this.dynamicDatabaseManager = dynamicDatabaseManager;
	}

}
